package com.protocols.sctp.m3ua.sccp.tcap;

import java.io.Serializable;

import com.protocols.DummyPayload;
import com.protocols.GeneralProtocolData;
import com.protocols.OctaveInteger;
import com.protocols.ProtoOperations;
import com.protocols.ProtocolStackException;
import com.protocols.sctp.m3ua.sccp.SccpUnitDataMsg;


public class TcapBegin implements GeneralProtocolData, Serializable{

	private TcapConstructor Begin = new TcapConstructor(0x62);
	private TcapPrimitiveUnitNumber SourceTransactionID = new TcapPrimitiveUnitNumber(0x48);
	private TcapConstructor DialogPortion = new TcapConstructor(0x6b);
	private TcapConstructor External = new TcapConstructor(0x28);
	private TcapPrimitiveUnitByteArray ObjectID = new TcapPrimitiveUnitByteArray(0x06);
	private TcapConstructor DialogAsID = new TcapConstructor(0xA0);
	private TcapConstructor DialogRequestPDU = new TcapConstructor(0x60);
	private TcapPrimitiveUnitNumber ProtocolVersion = new TcapPrimitiveUnitNumber(0x80);
	private TcapConstructor ApplicationContextContainer = new TcapConstructor(0xA1);
	private TcapPrimitiveUnitNumber ApplicationContext = new TcapPrimitiveUnitNumber(0x06);
	private TcapConstructor UserInformationContainer = new TcapConstructor(0xbe);
	private TcapConstructor UserInformationElement1 = new TcapConstructor(0x28);
	private TcapPrimitiveUnitByteArray DirectReference = new TcapPrimitiveUnitByteArray(0x06);
	private TcapPrimitiveUnitByteArray InDirectReference = new TcapPrimitiveUnitByteArray(0x02);
	private TcapPrimitiveUnitByteArray SingleANSEncoding = new TcapPrimitiveUnitByteArray(0xa0);
	private TcapPrimitiveUnitByteArray OctatAlignEncoding = new TcapPrimitiveUnitByteArray(0x81);
	private TcapPrimitiveUnitByteArray ArbitaryEncoding = new TcapPrimitiveUnitByteArray(0x82);
	public TcapConstructor ComponentPortion = new TcapConstructor(0b01101100);

	
	public TcapBegin() {

		Begin.addElement(SourceTransactionID);
		Begin.addElement(DialogPortion);
		DialogPortion.addElement(External);
		External.addElement(ObjectID);
		External.addElement(DialogAsID);
		DialogAsID.addElement(DialogRequestPDU);
		DialogRequestPDU.addElement(ProtocolVersion);
		DialogRequestPDU.addElement(ApplicationContextContainer);
		ApplicationContextContainer.addElement(ApplicationContext);
		DialogRequestPDU.addElement(UserInformationContainer);
		UserInformationContainer.addElement(UserInformationElement1);
		UserInformationElement1.addElement(DirectReference);
		UserInformationElement1.addElement(InDirectReference);
		UserInformationElement1.addElement(SingleANSEncoding);
		UserInformationElement1.addElement(OctatAlignEncoding);
		UserInformationElement1.addElement(ArbitaryEncoding);
		Begin.addElement(ComponentPortion);
		
		//ObjectID.setTagValue(new byte[] {00,0x11,(byte)0x86,0x05,01,01,01});
		//ProtocolVersion.setTagValue(0x0780);
		
		
	}

	public byte [] getByteArray(){	
		return Begin.getByteArray();
		

	}
	
	public void setObjectID(byte[] objectid){
		ObjectID.setTagValue(objectid);
	}
	
	public byte[] getObjectID(){
		return ObjectID.getTagValue();
	}
	
	public int getLength(){
		return getByteArray().length;
	}
	
	public void setProtocolVersion(long protocolversion){
		ProtocolVersion.setTagValue(protocolversion);
	}
	
	public long getProtocolVersion(){
		return ProtocolVersion.getTagValue();
	}
	
	
	public void setApplicationContext(long appcontext){
		ApplicationContext.setTagValue(appcontext);
	}
	
	public long getApplicationContext(){
		return ApplicationContext.getTagValue();
	}

	public long getSourceTransactionID() {
		return SourceTransactionID.getTagValue();
	}

	public void setSourceTransactionID(long sourceTransactionID) {
		SourceTransactionID.setTagValue( sourceTransactionID);
	}

	@Override
	public byte[] decode(byte[] input) throws ProtocolStackException {
	
		input=ProtoOperations.extractByteArray(input, 1, input.length-1);
		
		return Begin.decode(input);
	}

	public byte[] getSingleANSEncoding() {
		return SingleANSEncoding.getTagValue();
	}

	
	
	
}
